package com.thor.palmmall.rest.order.converter;

import java.util.ArrayList;
import java.util.List;

import org.springframework.core.convert.converter.Converter;

import com.thor.palmmall.rest.order.AGiftActivies;
import com.thor.palmmall.rest.order.ASection;
import com.thor.palmmall.spi.order.SGiftActivies;

public class AGiftActiviesConverter implements Converter<List<SGiftActivies>, List<AGiftActivies>> {
  public static AGiftActiviesConverter getInstance() {
    if (instance == null)
      instance = new AGiftActiviesConverter();
    return instance;
  }

  private static AGiftActiviesConverter instance;

  @Override
  public List<AGiftActivies> convert(List<SGiftActivies> sourceList) {
    if (sourceList == null || sourceList.size() == 0) {
      return null;
    }
    List<AGiftActivies> list = new ArrayList<AGiftActivies>();
    for (SGiftActivies source : sourceList) {
      AGiftActivies target = new AGiftActivies();

      target.setPromBillUuid(source.getPromBillUuid());
      target.setContract(source.getContract());
      target.setActivityName(source.getActivityName());
      target.setFullOrder(source.getFullOrder());
      target.setActivityType(source.getActivityType());
      target.setMinAmount(source.getMinAmount());
      target.setSegmentType(source.getSegmentType());
      if (source.getSections() != null) {
        target.setSections(ASectionConverter.getInstance().convert(source.getSections()));
      } else {
        target.setSections(new ArrayList<ASection>());
      }

      list.add(target);
    }
    return list;
  }
}
